package com.smartcruise.util.network.customerObserver;

import com.smartcruise.base.BaseNormalView;
import com.smartcruise.util.network.callBack.BaseCallBack;
import com.smartcruise.util.network.netUtils.NetContract;
import com.smartcruise.util.network.netUtils.Result;

/**
 * Created by FengChaoQun
 * on 2018/2/3 0003
 * BaseProgressObserver的简单实现 接受{@link Result}作为网络请求结果
 * 对返回的结果进行分类 然后交给{@link BaseCallBack}处理
 */

public class SimpleProgressObserverImp extends BaseProgressObserver<Result> {

    private BaseCallBack callBack;

    public SimpleProgressObserverImp(BaseNormalView baseNormalView, BaseCallBack baseCallBack) {
        super(baseNormalView);
        this.callBack = baseCallBack;
    }

    @Override
    public void onNext(Result result) {
        if (NetContract.isSuccess(result)) {
            callBack.onSuccess(result);
        } else {
            callBack.onFail(result);
        }
    }

    @Override
    public void onError(Throwable throwable) {
        super.onError(throwable);
        callBack.onError(throwable);
    }

}
